import 'package:bxultimate/domain/application/NewsCategory.dart';
import 'package:bxultimate/domain/application/examination/ExaminationAnswerCard.dart';
import 'package:bxultimate/domain/application/examination/ExaminationDto.dart';
import 'package:bxultimate/domain/application/examination/ExaminationJoinDto.dart';
import 'package:bxultimate/domain/application/examination/ExaminationQuestionDto.dart';
import 'package:bxultimate/domain/application/examination/ExaminationResult.dart';
import 'package:bxultimate/domain/application/pre_service/PreServiceEducationCarouselDto.dart';
import 'package:bxultimate/domain/application/questionnaire/QUestionnaireDetailDto.dart';
import 'package:bxultimate/domain/application/questionnaire/QuestionnaireDto.dart';
import 'package:bxultimate/domain/common/result.dart';
import 'package:bxultimate/domain/home/home_data_dto.dart';
import 'package:bxultimate/shared/util/util_http.dart';

class ApplicationRequest {
  // 获取banner
  static Future<List<PreServiceEducationCarouselDto>> getBannsArticle(
      pid) async {
    var response = await UtilHttp().get(
      '/cms/epsCategory/getBannsArticle?pid=${pid}',
    );
    return response['data']
        .map<PreServiceEducationCarouselDto>(
            (item) => PreServiceEducationCarouselDto.fromJson(item))
        .toList();
  }

  static Future<List<Article>> getArticleByType(page, size, pid) async {
    var response = await UtilHttp().get(
      '/cms/epsArticle/articleByType?pageNumber=${page}&pageSize=${size}&typeId=${pid}',
    );
    return response['data']['records']
        .map<Article>((item) => Article.fromJson(item))
        .toList();
  }

  // 文章
  static Future<List<NewsCategory>> getNewsCategory(pid) async {
    var response = await UtilHttp().get(
      '/cms/epsCategory/getCategory?pid=${pid}&isBanns=',
    );
    return response['data']
        .map<NewsCategory>((item) => NewsCategory.fromJson(item))
        .toList();
  }

  // 获取考试列表
  static Future<List<ExaminationDto>> getExaminationList(
      page, size, status) async {
    var response = await UtilHttp().get(
      '/app/andriod/examination/getExaminationList?pageNumber=${page}&pageSize=${size}&status=${status}',
    );
    return response['data']['records']
        .map<ExaminationDto>((item) => ExaminationDto.fromJson(item))
        .toList();
  }

  // 查看考试结果
  static Future<ExaminationResult> viewExamFinishResult(examId) async {
    var response = await UtilHttp().get(
      '/cms/examination/viewExamFinish?examId=${examId}',
    );
    return ExaminationResult.fromJson(response['data']);
  }

  // 获取答题卡
  static Future<List<ExaminationAnswerCard>> getExamDtk(examId) async {
    var response = await UtilHttp().get(
      '/cms/examination/getExamDtk?examId=${examId}&state=jx',
    );
    return response['data']
        .map<ExaminationAnswerCard>(
            (item) => ExaminationAnswerCard.fromJson(item))
        .toList();
  }

  // 开始考试
  static Future<ExaminationJoinDto> clickJoinExamination(
      examId, lat, lon, subCode) async {
    var response = await UtilHttp().get(
      '/cms/examination/clickJoinExamination?examId=${examId}&lat=${lat}&lon=${lon}&subCode=${subCode}',
    );
    return ExaminationJoinDto.fromJson(response['data']);
  }

  // 通过记录id获取题目
  static Future<ExaminationQuestionDto> getItemByDaanId(
      currentId, userAnswer, id, state) async {
    var response = await UtilHttp().get(
      '/cms/examination/getItemByDaanId?currentId=${currentId}&userAnswer=${userAnswer}&id=${id}&state=${state}',
    );
    return ExaminationQuestionDto.fromJson(response['data']);
  }

  // 提交试卷
  static Future<Result> submitExam(examId) async {
    var response = await UtilHttp().get(
      '/cms/examination/submitExam?examId=${examId}',
    );
    return Result.fromJson(response);
  }

  // 检测是否超时
  static Future<Result> checkExamIsTimeout(examId) async {
    var response = await UtilHttp().get(
      '/cms/examination/checkExamIsTimeout?examId=${examId}',
    );
    return Result.fromJson(response);
  }

  // 判断是否交过卷
  static Future<Result> panduanjiaojuan(examId) async {
    var response = await UtilHttp().get(
      '/cms/examination/panduanjiaojuan?examId=${examId}',
    );
    return Result.fromJson(response);
  }

  // 问卷列表
  static Future<List<QuestionnaireDto>> getQuestionnaireList() async {
    var response = await UtilHttp().post(
      '/cms/wjdc/getListUniApp',
    );
    return response['data']
        .map<QuestionnaireDto>((item) => QuestionnaireDto.fromJson(item))
        .toList();
  }

  // 问卷详情
  static Future<QUestionnaireDetailDto> getQuestionnaireDetail(id) async {
    var response = await UtilHttp().get(
      '/cms/wjdc/clickJoinWjdc?id=' + id,
    );
    return QUestionnaireDetailDto.fromJson(response['data']);
  }
  static Future<Result> submitWjdc(result) async {
    var response = await UtilHttp().get(
      '/cms/wjdc/submitWjdc?result=' + result,
    );
    return Result.fromJson(response);
  }
}
